package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.annotation.RequiresPermissionsDesc;
import com.cskaoyan.market.service.AdminConfigService;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/admin/config")
@RestController
public class AdminConfigController  {
    @Autowired
    AdminConfigService adminConfigService;

    @GetMapping("order")
    @RequiresPermissions("admin:config:order")
    @RequiresPermissionsDesc(menu = {"配置管理", "订单配置"},button = "Get订单")
    public Object getOrder() {
        Map<String,Object> map = adminConfigService.getOrderResponse();
        return ResponseUtil.ok(map);
    }

    @GetMapping("wx")
    @RequiresPermissions("admin:config:wx")
    @RequiresPermissionsDesc(menu = {"配置管理", "小程序配置"},button = "Get小程序")
    public Object getWx() {
        Map<String,Object> map = adminConfigService.getWxResponse();
        return ResponseUtil.ok(map);
    }

    @GetMapping("express")
    @RequiresPermissions("admin:config:express")
    @RequiresPermissionsDesc(menu = {"配置管理", "运费配置"},button = "Get运费")
    public Object getExpress() {
        Map<String,Object> map = adminConfigService.getExpressResponse();
        return ResponseUtil.ok(map);
    }

    @PostMapping("order")
    @RequiresPermissions("admin:config:order")
    @RequiresPermissionsDesc(menu = {"配置管理", "订单配置"},button = "Post订单")
    public Object postOrder(@RequestBody Map<String,String> marketOrder){
        adminConfigService.modifyOrder(marketOrder);
        return ResponseUtil.ok();
    }

    @PostMapping("wx")
    @RequiresPermissions("admin:config:wx")
    @RequiresPermissionsDesc(menu = {"配置管理", "小程序配置"},button = "Post小程序")
    public Object postWx(@RequestBody Map<String,String> marketWx){
        adminConfigService.modifyWx(marketWx);
        return ResponseUtil.ok();
    }

    @PostMapping("express")
    @RequiresPermissions("admin:config:express")
    @RequiresPermissionsDesc(menu = {"配置管理", "运费配置"},button = "Post运费")
    public Object postExpress(@RequestBody Map<String,String> marketExpress){
        adminConfigService.modifyExpress(marketExpress);
        return ResponseUtil.ok();
    }
}
